/*
 * Application.cpp
 *
 *  Created on: 2016年4月6日
 *      Author: terry
 */

#include "Application.h"
#include "Socket.h"
#include "CLog.h"
#include "Ffmpeg.h"

typedef comn::Singleton< Application >		ApplicationSingleton;


Application& Application::instance()
{
	return ApplicationSingleton::instance();
}

Application::Application()
{
}

Application::~Application()
{
}


int Application::init()
{
#ifdef WIN32
	CLog::setLogger(CLog::DEBUGWINDOW);
#else
	CLog::setLogger(CLog::COUT);
#endif

	comn::Socket::startup();

	av_register_all();
	avformat_network_init();

	return 0;
}

void Application::quit()
{
	m_casters.clear();

	comn::Socket::cleanup();
}


int Application::put(MediaCasterPtr& caster)
{
	if (!caster)
	{
		return -1;
	}

	return m_casters.put(caster);
}

MediaCasterPtr Application::get(int idx)
{
	if (idx < 0 || idx >= (int)m_casters.size())
	{
		return MediaCasterPtr();
	}
	return m_casters.getAt(idx);
}

MediaCasterPtr Application::remove(int idx)
{
	MediaCasterPtr caster;
	m_casters.remove(idx, caster);
	return caster;
}

